/* JS */


/* Navigation */

$(document).ready(function () {

    $(window).resize(function () {
        if ($(window).width() >= 765) {
            $(".sidebar #nav").slideDown(350);
        } else {
            $(".sidebar #nav").slideUp(350);
        }
    });


    $("#nav > li > a").on('click', function (e) {
        if ($(this).parent().hasClass("has_sub")) {
            e.preventDefault();
        }

        if (!$(this).hasClass("subdrop")) {
            // hide any open menus and remove all other classes
            $("#nav li ul").slideUp(350);
            $("#nav li a").removeClass("subdrop");

            // open our new menu and add the open class
            $(this).next("ul").slideDown(350);
            $(this).addClass("subdrop");
        } else if ($(this).hasClass("subdrop")) {
            $(this).removeClass("subdrop");
            $(this).next("ul").slideUp(350);
        }

    });
});

$(document).ready(function () {
    $(".sidebar-dropdown a").on('click', function (e) {
        e.preventDefault();

        if (!$(this).hasClass("open")) {
            // hide any open menus and remove all other classes
            $(".sidebar #nav").slideUp(350);
            $(".sidebar-dropdown a").removeClass("open");

            // open our new menu and add the open class
            $(".sidebar #nav").slideDown(350);
            $(this).addClass("open");
        } else if ($(this).hasClass("open")) {
            $(this).removeClass("open");
            $(".sidebar #nav").slideUp(350);
        }
    });

});

/* Widget close */

$('.wclose').click(function (e) {
    e.preventDefault();
    var $wbox = $(this).parent().parent().parent();
    $wbox.hide(100);
});

/* Widget minimize */

$('.wminimize').click(function (e) {
    e.preventDefault();
    var $wcontent = $(this).parent().parent().next('.widget-content');
    if ($wcontent.is(':visible')) {
        $(this).children('i').removeClass('icon-chevron-up');
        $(this).children('i').addClass('icon-chevron-down');
    } else {
        $(this).children('i').removeClass('icon-chevron-down');
        $(this).children('i').addClass('icon-chevron-up');
    }
    $wcontent.toggle(500);
});

/* Calendar */

$(document).ready(function () {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();


});

/* Progressbar animation */

setTimeout(function () {

    $('.progress-animated .progress-bar').each(function () {
        var me = $(this);
        var perc = me.attr("data-percentage");

        //TODO: left and right text handling

        var current_perc = 0;

        var progress = setInterval(function () {
            if (current_perc >= perc) {
                clearInterval(progress);
            } else {
                current_perc += 1;
                me.css('width', (current_perc) + '%');
            }

            me.text((current_perc) + '%');

        }, 600);

    });

}, 600);

/* Slider */

$(function () {

    // Vertical slider
    $("#eq > span").each(function () {
        // read initial values from markup and remove that
        var value = parseInt($(this).text(), 10);
        $(this).empty().slider({
            value: value,
            range: "min",
            animate: true,
            orientation: "vertical"
        });
    });
});


/* Support */

$(document).ready(function () {
    $("#slist a").click(function (e) {
        e.preventDefault();
        $(this).next('p').toggle(200);
    });
});

/* Scroll to Top */


$(".totop").hide();

$(function () {
    $(window).scroll(function () {
        if ($(this).scrollTop() > 300) {
            $('.totop').slideDown();
        } else {
            $('.totop').slideUp();
        }
    });

    $('.totop a').click(function (e) {
        e.preventDefault();
        $('body,html').animate({scrollTop: 0}, 500);
    });

});

/* jQuery Notification */

$(document).ready(function () {

    //setTimeout(function() {noty({text: '<strong>Howdy! Hope you are doing good...</strong>',layout:'topRight',type:'information',timeout:15000});}, 7000);

    //setTimeout(function() {noty({text: 'This is an all in one theme which includes Front End, Admin & E-Commerce. Dont miss it. Grab it now',layout:'topRight',type:'alert',timeout:13000});}, 9000);

});


$(document).ready(function () {

    $('.noty-alert').click(function (e) {
        e.preventDefault();
        noty({text: 'Some notifications goes here...', layout: 'topRight', type: 'alert', timeout: 2000});
    });

    $('.noty-success').click(function (e) {
        e.preventDefault();
        noty({text: 'Some notifications goes here...', layout: 'top', type: 'success', timeout: 2000});
    });

    $('.noty-error').click(function (e) {
        e.preventDefault();
        noty({text: 'Some notifications goes here...', layout: 'topRight', type: 'error', timeout: 2000});
    });

    $('.noty-warning').click(function (e) {
        e.preventDefault();
        noty({text: 'Some notifications goes here...', layout: 'bottom', type: 'warning', timeout: 2000});
    });

    $('.noty-information').click(function (e) {
        e.preventDefault();
        noty({text: 'Some notifications goes here...', layout: 'topRight', type: 'information', timeout: 2000});
    });

});


/* Modal fix */

$('.modal').appendTo($('body'));

/* Pretty Photo for Gallery*/
